const Router = require("koa-router")
const Server = require("./server")
const Check = require("./check")

/**
 * 路由对象
 * @type {Router}
 */
const router = new Router({
	prefix: '/coding'
})

/**
 * base64
 */
router.post('/base64', async function (ctx, next) {
		Check.base64(ctx)
		const data = Server.base64(ctx)
		ctx.sendSuccess(data)
})

/**
 * 图片转Base64
 */
router.post('/image-to-base64', async function (ctx, next) {
		Check.imageToBase64(ctx)
		const data = Server.imageToBase64(ctx)
		ctx.sendSuccess(data)
})

/**
 * base64转图片
 */
router.post('/base64-to-image', async function (ctx, next) {
		Check.base64ToImage(ctx)
		const data = Server.base64ToImage(ctx)
		ctx.sendSuccess(data)
})

/**
 * md5
 */
router.post('/md5', async function (ctx, next) {
		Check.md5(ctx)
		const data = Server.md5(ctx)
		ctx.sendSuccess(data)
})

/**
 * aes
 */
router.post('/aes', async function (ctx, next) {
		Check.aes(ctx)
		const data = Server.aes(ctx)
		ctx.sendSuccess(data)
})

module.exports = router
